package com.tsingteng.cosfun.ui.setting;

import com.tsingteng.cosfun.bean.ThirdBindBean;
import com.tsingteng.cosfun.callback.RxObserver;
import com.tsingteng.cosfun.mvp.presenter.BasePresenter;
import com.tsingteng.cosfun.utils.LogonUtils;

/**
 * 描述 :
 * 创建人: 肖利.
 * 时间:2018/8/22
 * qq(872179966)
 */

public class AccountManagePresenter extends BasePresenter<AccountMangeContract.IAccountMangeView> implements AccountMangeContract.IAccountMangePresenter {
    private AccountMangeContract.IAccountMangeView mView;
    private AccountMangeModel iAccountMangeModel;

    public AccountManagePresenter() {
        this.iAccountMangeModel = new AccountMangeModel() ;
    }

    @Override
    public void getThirdBindData(String thirdparty_token, String login_type, String nickname, String headpic, String open_id) {
        mView = getView();
        RxObserver<ThirdBindBean> rxObserver = new RxObserver<ThirdBindBean>(this) {
            @Override
            protected void onFaile(int errorCode, String errorMsg) {
                mView.showFail(errorMsg);
            }

            @Override
            protected void onSuccess(ThirdBindBean thirdBindBean) {
                mView.showThirdBindResult(thirdBindBean);
            }
        };
        iAccountMangeModel.getThirdBind(thirdparty_token,login_type,nickname,headpic,open_id,rxObserver);
        addDisposable(rxObserver);
    }


    @Override
    public void getAccountMangeMentData() {
        mView = getView();
        RxObserver<ThirdBindBean> rxObserver = new RxObserver<ThirdBindBean>(this) {
            @Override
            protected void onFaile(int errorCode, String errorMsg) {
                mView.showFail(errorMsg);
            }

            @Override
            protected void onSuccess(ThirdBindBean thirdBindBean) {
                mView.showAccountMangeMent(thirdBindBean);
            }
        };
        iAccountMangeModel.getAccountMangeMentData(String.valueOf(LogonUtils.getProFildId()),rxObserver);
        addDisposable(rxObserver);
    }

    @Override
    public void getThirdUnBind(String untie_type) {
        mView = getView();
        RxObserver<Integer> rxObserver = new RxObserver<Integer>(this) {
            @Override
            protected void onFaile(int errorCode, String errorMsg) {
                mView.showFail(errorMsg);
            }

            @Override
            protected void onSuccess(Integer integer) {
                mView.showThirdUnBindResult(integer);
            }
        };
        iAccountMangeModel.getThirdUnBind(untie_type,rxObserver);
        addDisposable(rxObserver);
    }
}
